<template>
  <div class="list-container">
    <div class="list-top-bar">
      <el-link @click="goBack" :underline="false" class="back-link">
        <el-icon><ArrowLeft /></el-icon>
        返回
      </el-link>
    </div>
    <div class="list-header">
      <span class="col subject">主题</span>
      <span class="col sender">发件人</span>
      <span class="col date">时间</span>
      <span class="col status">状态</span>
    </div>
    <DeletedItem
      v-for="item in mails"
      :key="item.id"
      :mail="item"
    />
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getMailListAPI, type MailListItem } from '@/api/mailsAPI'
import { useRouter } from 'vue-router'
import DeletedItem from './DeletedItem.vue'
import { ArrowLeft } from '@element-plus/icons-vue'

const router = useRouter()
const mails = ref<MailListItem[]>([])

const fetchMails = async () => {
  const res = await getMailListAPI('deleted')
  if (res.code === 200) mails.value = res.data
}

const goBack = () => {
  router.push('/home')
}

onMounted(fetchMails)
</script>

<style scoped>
.list-container {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(209, 96, 83, 0.04);
  padding: 0;
}

.list-top-bar {
  display: flex;
  align-items: center;
  padding: 18px 24px 0 24px;
  gap: 16px;
  margin-bottom: 8px;
}
.back-link {
  color: #aaa;
  font-size: 16px;
  display: flex;
  align-items: center;
  transition: color 0.2s;
  font-weight: 500;
  margin-right: 12px;
}
.back-link .el-icon {
  margin-right: 4px;
  font-size: 18px;
}
.back-link:hover {
  color: #d16053;
}

.list-header {
  display: flex;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid #eee;
  width: 100%;
  box-sizing: border-box;
  font-weight: bold;
  background: #f5f5f5;
  font-size: 16px;
}
.col.subject { display: inline-block; width: 320px; padding-right: 12px; }
.col.sender { display: inline-block; width: 300px; padding-right: 12px; }
.col.date { display: inline-block; width: 300px; padding-right: 12px; }
.col.status { display: inline-block; width: 300px; }
</style>
